import 'dart:convert';
import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_picker/picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:taonile/config/config.dart';
import 'package:taonile/entity/upimg_entity.dart';
import 'package:taonile/routers/routers.dart';
import 'package:taonile/utils/singleton_manager.dart';

import '../entity/receipt_address_entity.dart';
import '../entity/refund_reason_entity.dart';
import '../http/api.dart';
import '../utils/oss_upload_util.dart';
import '../views/number_controller_widget.dart';

///
/// 申请退款 OR 申请退货退款
///
class OrderApplyRefund extends StatefulWidget {
  var type = '1';
  var orderNo = '';
  var goodsId = '';
  var img = '';
  var name = '';
  var spec = '';
  var price = '';
  var num = '';

  OrderApplyRefund(
      {Key? key,
      this.type = '1',
      this.orderNo = '',
      this.goodsId = '',
      this.img = '',
      this.name = '',
      this.spec = '',
      this.price = '',
      this.num = ''})
      : super(key: key);

  @override
  State<OrderApplyRefund> createState() => _OrderApplyRefundState();
}

class _OrderApplyRefundState extends State<OrderApplyRefund> {
  String _content = '';
  String reason = '请选择';
  List<UpImgEntity> upList = [];
  int maxImgNum = 3;
  String inputNum = '1';
  double refundMoney = 0;
  String jiName = '请选择';
  String jiAddress = '';
  String addressId = '';
  String title = '';

  String subTitle = '退换商品';
  String subTitle2 = '退款信息';
  String subTitle3 = '退款原因';

  ReceiptAddressData receiptAddressData = ReceiptAddressData();

  List<RefundReasonData> reasonList = [];

  @override
  void initState() {
    super.initState();
    upList.add(UpImgEntity(1, ''));
    refundMoney = double.parse(widget.price);
    getRefundMoney();

    if (widget.type == '1') {
      title = '申请退款';
      subTitle = '退换商品';
      subTitle2 = '退款信息';
      subTitle3 = '退款原因';
    } else if (widget.type == '2') {
      title = '申请退货退款';
      subTitle = '退换商品';
      subTitle2 = '退款信息';
      subTitle3 = '退款原因';
    } else {
      title = '补发商品';
      subTitle = '售后商品';
      subTitle2 = '售后信息';
      subTitle3 = '申请原因';
    }
  }

  String getImgLink() {
    StringBuffer sb = StringBuffer();
    for (int i = 0; i < upList.length; i++) {
      if (upList[i].type == 2) {
        sb.write(upList[i].imgUrl);
        sb.write(',');
      }
    }
    String result = sb.toString();
    if (result.length > 1) {
      result = result.substring(0, result.length - 1);
    }
    return result;
  }

  getRefundMoney() {
    double input = double.parse(inputNum);
    double price = double.parse(widget.price);
    refundMoney = input * price;
  }

  refundOrderPost() async {
    if (reason == '请选择') {
      EasyLoading.showToast('请选择申请原因');
      return;
    }

    if (int.parse(widget.num) < int.parse(inputNum)) {
      EasyLoading.showToast('最多可退${widget.num}件');
      return;
    }

    if (widget.type == '2' && receiptAddressData.id.isEmpty) {
      EasyLoading.showToast('请选择地址');
      return;
    }

    //正常退款参数
    var param = {
      'type': widget.type,
      'order_no': widget.orderNo,
      'order_goods_id': widget.goodsId,
      'refund_reason': reason,
      'num': inputNum,
      'describe': _content,
      'image': getImgLink(),
    };

    //退货退款，则要加参数
    if (widget.type == '2' || widget.type == '3') {
      param['phone'] = receiptAddressData.mobile;
      param['address'] = jiAddress;
      param['name'] = receiptAddressData.username;
      param['return_method'] = '1';
    }

    dynamic result = await Api.applyRefund(param);
    var jsonResult = jsonDecode(jsonEncode(result));
    if (jsonResult['code'] == 1) {
      EasyLoading.showToast("申请提交成功，等待审核");
      Routes.router.pop(context, {'result': 1});
    }
  }

  chooseImage() async {
    final ImagePicker _picker = ImagePicker();
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    String? imgPah = image?.path;
    if (imgPah != null) {
      LogUtil.v(imgPah, tag: '选择的图片路径=');
      EasyLoading.show(status: 'loading...');
      String result = await UploadOss.upload(File(imgPah), fileType: UploadOss.getFileType(imgPah));
      LogUtil.v(result);
      setState(() {
        if (upList.length == maxImgNum) {
          upList[maxImgNum - 1] = UpImgEntity(2, result);
        } else {
          upList.insert(0, UpImgEntity(2, result));
        }
      });
      EasyLoading.dismiss();
    }
  }

  deleteImg(int index) {
    setState(() {
      upList.removeAt(index);
      int temp = 0;
      for (var item in upList) {
        if (item.type == 1) {
          temp++;
        }
      }
      if (temp == 0) {
        upList.add(UpImgEntity(1, ''));
      }
    });
  }

  Widget getListItem(int index) {
    return Container(
      height: 120.w,
      width: 120.w,
      alignment: Alignment.center,
      margin: EdgeInsets.only(right: 15.w),
      child: Stack(
        children: [
          Visibility(
            visible: upList[index].type == 0,
            child: Container(
              width: double.infinity,
              height: double.infinity,
              decoration: BoxDecoration(
                color: Config.colorBg2,
                borderRadius: BorderRadius.circular(10.w),
              ),
            ),
          ),
          Visibility(
            visible: upList[index].type == 1,
            child: Container(
              width: double.infinity,
              height: double.infinity,
              decoration: BoxDecoration(
                color: Config.colorBg2,
                borderRadius: BorderRadius.circular(10.w),
              ),
              child: InkWell(
                onTap: () {
                  chooseImage();
                },
                child: Icon(
                  Icons.upload_outlined,
                  size: 50.w,
                  color: Config.colorText2,
                ),
              ),
            ),
          ),
          Visibility(
            visible: upList[index].type == 2,
            child: Container(
              decoration: BoxDecoration(
                color: Config.colorBg2,
                borderRadius: BorderRadius.circular(10.w),
              ),
              child: Stack(
                children: [
                  ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(8.w)),
                    child: CachedNetworkImage(
                      imageUrl: upList[index].imgUrl,
                      fit: BoxFit.fill,
                      width: double.infinity,
                      height: double.infinity,
                      errorWidget: (context, url, error) {
                        return Image.asset(
                          'assets/images/bg_default_400.png',
                          width: double.infinity,
                          height: double.infinity,
                          fit: BoxFit.fill,
                        );
                      },
                    ),
                  ),
                  Positioned(
                    right: 0,
                    child: InkWell(
                      onTap: () {
                        deleteImg(index);
                      },
                      child: Container(
                        width: 40.w,
                        height: 40.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Config.colorBg2,
                          borderRadius: BorderRadius.circular(20.w),
                        ),
                        child: Icon(
                          Icons.close_outlined,
                          size: 36.w,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  getReasonList() {
    if (widget.type == '1') {
      return List.generate(SingletonManager.instance.refundReason.length,
          (index) => SingletonManager.instance.refundReason[index].title);
    } else if (widget.type == '2') {
      return List.generate(SingletonManager.instance.returnReason.length,
          (index) => SingletonManager.instance.returnReason[index].title);
    } else {
      return List.generate(SingletonManager.instance.buReason.length,
          (index) => SingletonManager.instance.buReason[index].title);
    }
  }

  refundOrder(BuildContext context) async {
    Picker(
        adapter: PickerDataAdapter(pickerData: getReasonList(), isArray: false),
        height: 350.w,
        headerDecoration: BoxDecoration(
          color: Config.colorWhite,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.w),
            topRight: Radius.circular(20.w),
          ),
        ),
        itemExtent: 70.w,
        confirmText: '确定',
        cancelText: '取消',
        columnPadding: EdgeInsets.all(15.w),
        onConfirm: (picker, list) {
          // LogUtil.v(SingletonManager.instance.refundReason[list[0]]);
          setState(() {
            if (widget.type == '1') {
              reason = SingletonManager.instance.refundReason[list[0]].title;
            } else if (widget.type == '2') {
              reason = SingletonManager.instance.returnReason[list[0]].title;
            } else {
              reason = SingletonManager.instance.buReason[list[0]].title;
            }
          });
        }).showModal(context, backgroundColor: Colors.transparent);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      appBar: AppBar(
        title: Text(title),
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        margin: EdgeInsets.symmetric(vertical: 0.w, horizontal: 30.w),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                decoration: BoxDecoration(
                  color: Config.colorWhite,
                  borderRadius: BorderRadius.circular(10.w),
                ),
                width: double.infinity,
                margin: EdgeInsets.only(top: 25.w),
                padding: EdgeInsets.only(left: 25.w, right: 25.w, top: 20.w),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(
                          child: Text(
                            subTitle,
                            style: TextStyle(fontSize: 26.sp),
                          ),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Container(
                      padding: EdgeInsets.only(top: 8.w),
                      height: 140.w,
                      decoration: BoxDecoration(
                        border: Border(bottom: BorderSide(color: Config.colorDivider, width: 1.w)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            width: 100.w,
                            height: 100.w,
                            margin: EdgeInsets.only(right: 20.w),
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(5),
                              child: CachedNetworkImage(
                                imageUrl: widget.img,
                                fit: BoxFit.fill,
                                width: 100.w,
                                height: 100.w,
                                errorWidget: (context, url, error) {
                                  return Image.asset(
                                    'assets/images/bg_default_400.png',
                                    width: 100.w,
                                    height: 100.w,
                                    fit: BoxFit.fill,
                                  );
                                },
                              ),
                            ),
                          ),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                width: 520.w,
                                child: Text(
                                  widget.name,
                                  softWrap: false,
                                  style: TextStyle(color: (Config.colorText1), fontSize: 22.w),
                                ),
                              ),
                              Container(
                                width: 520.w,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      widget.spec,
                                      softWrap: true,
                                      style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
                                    ),
                                    Text(
                                      "X${widget.num}",
                                      softWrap: true,
                                      style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
                                    ),
                                  ],
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(top: 9.w),
                              ),
                              Text(
                                '${widget.price}金券 ',
                                softWrap: true,
                                style: TextStyle(color: (Config.colorText1), fontSize: 20.w),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                decoration: BoxDecoration(
                  color: Config.colorWhite,
                  borderRadius: BorderRadius.circular(10.w),
                ),
                width: double.infinity,
                margin: EdgeInsets.only(top: 25.w),
                padding: EdgeInsets.only(left: 25.w, right: 25.w, top: 20.w, bottom: 20.w),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(
                          child: Text(
                            subTitle2,
                            style: TextStyle(fontSize: 26.sp),
                          ),
                        ),
                      ],
                    ),
                    Visibility(
                      visible: widget.type == '1',
                      child: Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '1',
                      child: Container(
                        height: 70.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '货物状态',
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                              ],
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '未收到货',
                                  style: TextStyle(fontSize: 24.sp, color: Config.colorText3),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Container(
                      height: 70.w,
                      child: InkWell(
                        onTap: () => refundOrder(context),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  subTitle3,
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                              ],
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  reason,
                                  style: TextStyle(fontSize: 24.sp, color: Config.colorText3),
                                ),
                                Icon(
                                  Icons.arrow_forward_ios,
                                  size: 22.w,
                                  color: Config.colorText3,
                                )
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '1' || widget.type == '2',
                      child: Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '1' || widget.type == '2',
                      child: Container(
                        height: 70.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '商品件数',
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                                Text(
                                  '最多可退${widget.num}件',
                                  style: TextStyle(fontSize: 22.sp, color: Config.colorText3),
                                ),
                              ],
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                NumberControllerWidget(
                                  height: 45.w,
                                  width: 80.w,
                                  maxNum: int.parse(widget.num),
                                  numText: inputNum,
                                  addValueChanged: (num) {
                                    setState(() {
                                      inputNum = num.toString();
                                      getRefundMoney();
                                    });
                                  },
                                  removeValueChanged: (num) {
                                    setState(() {
                                      inputNum = num.toString();
                                      getRefundMoney();
                                    });
                                  },
                                  updateValueChanged: (num) {},
                                )
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '1' || widget.type == '2',
                      child: Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '1' || widget.type == '2',
                      child: Container(
                        height: 70.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '退款金额',
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                                Text(
                                  '不可修改',
                                  style: TextStyle(fontSize: 22.sp, color: Config.colorText3),
                                ),
                              ],
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '$refundMoney金券',
                                  style: TextStyle(fontSize: 26.sp, color: Colors.red),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '3',
                      child: Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                    ),
                    Visibility(
                      visible: widget.type == '3',
                      child: Container(
                        height: 120.w,
                        child: InkWell(
                          onTap: () {
                            Routes.navigateTo(context, Routes.mineAddressChoose).then((value) {
                              setState(() {
                                receiptAddressData = value;
                                addressId = receiptAddressData.id;
                                jiName =
                                    '${receiptAddressData.username}  ${receiptAddressData.mobile}';
                                jiAddress =
                                    '${receiptAddressData.provinceName}${receiptAddressData.cityName}${receiptAddressData.areaName}${receiptAddressData.detail}';
                              });
                            });
                          },
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '收货地址',
                                    style: TextStyle(fontSize: 25.sp),
                                  ),
                                ],
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    padding: EdgeInsets.only(left: 50.w),
                                    width: 500.w,
                                    height: 120.w,
                                    child: Column(
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      crossAxisAlignment: CrossAxisAlignment.end,
                                      children: [
                                        Text(
                                          jiName,
                                          style:
                                              TextStyle(fontSize: 24.sp, color: Config.colorText1),
                                        ),
                                        Visibility(
                                          visible: addressId.isNotEmpty,
                                          child: Text(
                                            jiAddress,
                                            textAlign: TextAlign.right,
                                            style: TextStyle(
                                                fontSize: 22.sp,
                                                height: 1.6,
                                                color: Config.colorText2),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(right: 10.w),
                                  ),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 22.w,
                                    color: Config.colorText3,
                                  )
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Visibility(
                visible: widget.type == '2',
                child: Container(
                  decoration: BoxDecoration(
                    color: Config.colorWhite,
                    borderRadius: BorderRadius.circular(10.w),
                  ),
                  width: double.infinity,
                  margin: EdgeInsets.only(top: 25.w),
                  padding: EdgeInsets.only(left: 25.w, right: 25.w, top: 20.w, bottom: 20.w),
                  child: Column(
                    children: [
                      Container(
                        height: 110.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  '退货方式',
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                                Text(
                                  '由您自行选择快递，邮寄回商家，\n邮寄后需要您自行填写运单号',
                                  style: TextStyle(fontSize: 22.sp, color: Config.colorText3),
                                ),
                              ],
                            ),
                            Row(
                              children: [
                                Text(
                                  '自行寄回',
                                  style: TextStyle(fontSize: 25.sp),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Container(
                        height: 120.w,
                        child: InkWell(
                          onTap: () {
                            Routes.navigateTo(context, Routes.mineAddressChoose).then((value) {
                              setState(() {
                                receiptAddressData = value;
                                addressId = receiptAddressData.id;
                                jiName =
                                    '${receiptAddressData.username}  ${receiptAddressData.mobile}';
                                jiAddress =
                                    '${receiptAddressData.provinceName}${receiptAddressData.cityName}${receiptAddressData.areaName}${receiptAddressData.detail}';
                              });
                            });
                          },
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '寄件地址',
                                    style: TextStyle(fontSize: 25.sp),
                                  ),
                                ],
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Container(
                                    padding: EdgeInsets.only(left: 50.w),
                                    width: 500.w,
                                    height: 120.w,
                                    child: Column(
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      crossAxisAlignment: CrossAxisAlignment.end,
                                      children: [
                                        Text(
                                          jiName,
                                          style:
                                              TextStyle(fontSize: 24.sp, color: Config.colorText1),
                                        ),
                                        Visibility(
                                          visible: addressId.isNotEmpty,
                                          child: Text(
                                            jiAddress,
                                            textAlign: TextAlign.right,
                                            style: TextStyle(
                                                fontSize: 22.sp,
                                                height: 1.6,
                                                color: Config.colorText2),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(right: 10.w),
                                  ),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 22.w,
                                    color: Config.colorText3,
                                  )
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                decoration: BoxDecoration(
                  color: Config.colorWhite,
                  borderRadius: BorderRadius.circular(10.w),
                ),
                width: double.infinity,
                margin: EdgeInsets.only(top: 25.w),
                padding: EdgeInsets.only(left: 25.w, right: 25.w, top: 20.w, bottom: 20.w),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(
                          child: Text(
                            '补充描述',
                            style: TextStyle(fontSize: 26.sp),
                          ),
                        ),
                      ],
                    ),
                    Divider(
                      color: Config.colorDivider,
                      height: 40.w,
                      thickness: 2.w,
                    ),
                    Container(
                      height: 180.w,
                      padding: EdgeInsets.all(10.w),
                      decoration: BoxDecoration(
                        color: Config.colorBg2,
                        borderRadius: BorderRadius.circular(10.w),
                      ),
                      child: TextField(
                        keyboardType: TextInputType.text,
                        textAlign: TextAlign.justify,
                        obscureText: false,
                        maxLength: 200,
                        maxLines: 10,
                        onChanged: (value) {
                          setState(() {
                            _content = value;
                          });
                        },
                        style: TextStyle(fontSize: 24.sp, color: Config.colorText1),
                        decoration: const InputDecoration(
                          hintStyle: TextStyle(color: Config.colorText3),
                          hintText: "补充描述，有助于商家更好的处理售后问题",
                          // counterText: '',
                          isDense: true,
                          border: InputBorder.none,
                          contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                        ),
                      ),
                    ),
                    Stack(
                      children: [
                        Container(
                          padding: EdgeInsets.only(top: 50.w),
                          child: Text(
                            '上传凭证(最多三张)',
                            style: TextStyle(fontSize: 22.sp, color: Config.colorText1),
                          ),
                        ),
                        Container(
                          height: 120.w,
                          width: double.infinity,
                          margin: EdgeInsets.only(top: 10.w, left: 245.w),
                          child: ListView.builder(
                            physics: const NeverScrollableScrollPhysics(),
                            itemCount: upList.length,
                            scrollDirection: Axis.horizontal,
                            padding: EdgeInsets.symmetric(vertical: 1.w, horizontal: 1.w),
                            itemBuilder: (BuildContext context, int index) {
                              return getListItem(index);
                            },
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                width: 750.w,
                height: 100.w,
                padding: EdgeInsets.symmetric(vertical: 8.w, horizontal: 8.w),
                margin: EdgeInsets.only(top: 25.w),
                child: ElevatedButton(
                  clipBehavior: Clip.antiAlias,
                  onPressed: () => {refundOrderPost()},
                  style: ElevatedButton.styleFrom(shape: const StadiumBorder()),
                  child: Text('提交'),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
